package main.niit.dao;

import main.niit.pojo.*;
import main.niit.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Get4{
    public List<AreaTop3Product> getall() throws Exception {
        Connection connection=JDBCUtils.getConnection();


        List<AreaTop3Product> list4= new ArrayList<>();

        PreparedStatement ps4=null;


        ResultSet resultSet4=null;

        try {
            String sql4 = "SELECT area, productid, clickCount FROM area_top3_product ;";
            ps4 = connection.prepareStatement(sql4);
            resultSet4 = ps4.executeQuery();
            while (resultSet4.next()) {
                AreaTop3Product areaTop3Product= new AreaTop3Product();
                areaTop3Product.setArea(resultSet4.getString("area"));
                areaTop3Product.setProductId(resultSet4.getLong("productId"));
                areaTop3Product.setClickCount(resultSet4.getLong("clickCount"));
                list4.add(areaTop3Product);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            JDBCUtils.close(ps4,connection);
        }

        return list4;

    }
}
